package com.lqk;

/**
 * @author liqiankun
 * @date 2022/11/22 19:41
 * @description 静态代理
 *
 * 特点: 代理类和被代理类在编译期间, 就确定下来了
 **/
public class StaticProxy {
    public static void main(String[] args) {
        // 创建被代理类对象
        ClothFactory nick = new NickClothFactory();
        // 创建代理类对象
        ClothFactory proxyClothFactory = new ProxyClothFactory(nick);
        proxyClothFactory.produceCloth();
    }
}

interface ClothFactory{
    /**
     * 生产衣服
     */
    void produceCloth();
}

/**
 * 代理类
 */
class ProxyClothFactory implements ClothFactory{

    /**
     * 用被代理类对象进行实例化
      */
    private final ClothFactory factory;

    public ProxyClothFactory(ClothFactory factory) {
        this.factory = factory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一些准备工作");

        factory.produceCloth();

        System.out.println("代理工厂做一些收尾工作");

    }
}
/**
 * 被代理类
 */
class NickClothFactory implements ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("Nick工厂生产一批运动服");
    }
}